<style>
    .show-menu a,.news-item a{margin-right:10px}
</style>


<div class="row">
    <div class="col-md-3">
        <div class="panel panel-default" style="min-height:600px">
            <div class="panel-heading">
                <?php if (!empty($cur_user["isSuperAdmin"])) : ?>
                    <span style="float: right;cursor: pointer" class="glyphicon glyphicon-plus btn-add-top" aria-hidden="true"></span>
                <?php endif; ?>
                <h3 class="panel-title">栏目列表</h3>
            </div>
            <div class="list-group">
                <?php foreach ($root_menu_list as $root_menu) { ?>
                    <?php if (isset($children_menu_list[$root_menu["objectId"]])) : ?>
                        <a data-id="<?=$root_menu["objectId"]?>" class="list-group-item <?= (isset($this->params['left_menu_active_id'])&&$this->params['left_menu_active_id'] == $root_menu["objectId"]) ? 'active' : '' ?>" href="/admin/content-list?menu_id=<?= $root_menu["objectId"] ?>">
                            <span class="ui-icon ui-icon-triangle-1-se"></span><?= $root_menu["menu_name"] ?>
                        </a>
                    <?php else: ?>
                        <a data-id="<?=$root_menu["objectId"]?>" class="list-group-item <?= (isset($this->params['left_menu_active_id'])&&$this->params['left_menu_active_id'] == $root_menu["objectId"]) ? 'active' : '' ?>" href="/admin/content-list?menu_id=<?=$root_menu["objectId"] ?>">
                            <span style="padding-left: 20px"><?= $root_menu["menu_name"] ?></span></a>
                    <?php endif; ?>
                    <?php if (isset($children_menu_list[$root_menu["objectId"]])) : ?>
                        <?php foreach ($children_menu_list[$root_menu["objectId"]] as $child_menu) { ?>
                            <a data-id="<?=$child_menu["objectId"]?>" class="list-group-item <?= (isset($this->params['left_menu_active_id'])&&$this->params['left_menu_active_id'] == $child_menu["objectId"]) ? 'active' : '' ?>" href="/admin/content-list?menu_id=<?= $child_menu["objectId"] ?>">
                                <span style="padding-left: 40px"><?= $child_menu["menu_name"] ?></span>
                            </a>
                        <?php } ?>
                    <?php endif; ?>
                <?php } ?>
            </div>
        </div>
    </div>
    <div class="col-md-9">
        <div class="panel panel-default">
            <div class="panel-heading">
                <a  style="float: right" href="javascript:;" class="add"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增文章</a>
                <h3 class="panel-title">内容列表</h3>
            </div>
            <div class="panel-body" style="min-height: 400px;margin-top: -15px">
                <?php if (!empty($right_content_list["content_list"])) : ?>
                    <?php foreach ($right_content_list["content_list"] as $content) { ?>
                        <div class="news-item">
                            <div style="float: right;">
                                <a href="javascript:;" class="btn-del" data-id="<?= $content["objectId"] ?>">删除</a>
                                <a href="javascript:;" class="edit" data-id="<?= $content["objectId"] ?>">编辑</a>
                            </div>
                            <a target="_blank" href="/home/content?id=<?= $content["objectId"] ?>"><?= $content["title"] ?></a>
                        </div>
                    <?php } ?>
                    <div><?= $right_content_list["page_html"] ?></div>
                <?php else: ?>
                    <div style="height:350px;text-align:center;padding-top: 160px ">当前栏目下文章为空，快来<a href="javascript:;" class="add">新增</a>一个吧！</div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>


<div id="dialog-confirm" title="提示" style="display: none">
    <p>确实要删除当前记录吗？</p>
</div>

<script>
    $( function() {
        $(".btn-del").on("click",function(){
            var content_id=$(this).attr("data-id");
            $( "#dialog-confirm" ).dialog({
                resizable: false,
                height: "auto",
                width: 400,
                modal: true,
                buttons: {
                    "确认": function() {
                        $( this ).dialog( "close" );
                        $.ajax({
                            type: "post",
                            url: "/admin/delete-content",
                            data: "content_id="+content_id,
                            success: function(msg){
                                toastr.success('删除成功');
                                window.location.href=window.location.href;
                            },
                            error:function(){
                                toastr.success('删除失败');
                                window.location.href=window.location.href;
                            }
                        });
                    },
                    取消: function() {
                        $( this ).dialog( "close" );
                    }
                }
            });
        });

        $(".add").on("click",function(){
            window.location.href="content-edit?menu_id="+(tplData.cur_menu.objectId)+"&mode=1&return_url="+encodeURI(tplData.cur_url);
        })

        $(".edit").on("click",function(){
            window.location.href="content-edit?menu_id="+(tplData.cur_menu.objectId)+"&mode=2&content_id="+$(this).attr("data-id")+"&return_url="+encodeURI(tplData.cur_url);
        })
    } );
</script>